package com.changpei.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.changpei.common.result.Result;
import com.changpei.core.service.OauthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 *
 *
 * @author Way on 2021/8/6
 */
@RestController
@RequestMapping("/oauth")
@CrossOrigin
public class OauthController {

    @Autowired
    private OauthService oauthService;

    /**
     * 用户申请令牌
     *
     * @param code
     * @return
     * @throws Exception
     */
    @PostMapping("/token")
    public JSONObject getToken(String code) throws Exception {
        return oauthService.getToken(code);
    }

    /**
     * 校验令牌是否有效
     *
     * @param token
     * @return
     * @throws Exception
     */
    @PostMapping("/verify")
    public Boolean verify(String token) {
        return oauthService.verify(token);
    }

    /**
     * 用户授权之后更新用户信息
     * @param params
     * @return
     */
    @PostMapping("/update")
    public Result<Boolean> updateUserInfo(@RequestBody Map<String, Object> params) {
        return Result.ok(oauthService.updateUserInfo(params));
    }
}
